﻿using DGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;



namespace Tab2Sql
{
    /// <summary>
    ///
    /// </summary>
    public class SqlDirect
    {
        DGen.db dbConn;
        /// <summary>
        ///
        /// </summary>
        public SqlDirect ()
        {
            //quick route
            string serverName = Properties.Settings.Default.DBServer;
            string dbName = Properties.Settings.Default.DBName;
            bool useIntegrated = true;

            dbConn = new DGen.db (serverName, dbName, useIntegrated);


        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sqlStatement">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public string SRun(string sqlStatement)
        {
            var dt = dbConn.RenderSQL(sqlStatement);
            return DGen.DText.ObjectToString.DataTableToString(dt, "\t");
        }
/// <summary>
/// 
/// </summary>
/// <param name="sqlStatement">
/// A <see cref="System.String"/>
/// </param>
/// <returns>
/// A <see cref="System.String"/>
/// </returns>
        public string Prettify(string sqlStatement)
        {
            string procName = "spPrettify";
            
            SqlParameter p1 = new SqlParameter("Code",sqlStatement);
            //System.Windows.Forms.RichTextBox
            //System.Windows.Forms.DataFormats.
     
            var dt=dbConn.RenderSQL(procName, p1);
            string htmlText = dt.Rows[0][0].ToString();
            return htmlText;
            

        }


    }
}
